package com.htzg.log4j2.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zalando.logbook.BodyFilter;

import java.nio.charset.Charset;

@Slf4j
@Configuration
public class LogbookConfig {

    @Bean
    public BodyFilter bodyFilter() {
        return BodyFilter.merge((mediaType, body) -> body, (mediaType, body) -> {
            //日志中文乱码问题处理
            if (body != null && !body.equals("")) {
                return new String(body.getBytes(Charset.forName("ISO-8859-1")));
            }
            return body;
        });
    }

}
